// ========================================================
// Des：
// Autor：Mr.H 
// CreateTime：2024/04/06 21:19:00
// 版 本：v 1.0
// ========================================================

using UnityEngine;

public class PlayerObj : TankBaseObj
{
    public WeaponObj nowWeapon;
    public Transform weaponPos;


    public override void Fire()
    {
        if (nowWeapon != null)
        {
            nowWeapon.Fire();
        }
    }

    public override void Wound(TankBaseObj other)
    {
        base.Wound(other);

        //更新面板血条
        GamePanel.Instance.UpdateHP(this.maxHp, this.hp);
    }
    private void Update()
    {
        //前进
        this.transform.Translate(Input.GetAxis("Vertical") * Vector3.forward * moveSpeed * Time.deltaTime);
        //旋转
        this.transform.Rotate(Input.GetAxis("Horizontal") * Vector3.up * roundSpeed * Time.deltaTime);
        //鼠标左右控制炮台  控制
        //鼠标轴向
        tankHead.transform.Rotate(Input.GetAxis("Mouse X") * Vector3.up * headRoundSpeed * Time.deltaTime);
        //开火
        if (Input.GetMouseButtonDown(0))
        {
            Fire();
        }
    }


    public void ChangeWeapon(GameObject weapon)
    {
        if (nowWeapon != null)
        {
            //删除当前武器
            Destroy(nowWeapon.gameObject);
            nowWeapon = null;
        }

        //切换武器 设置父对象  false保证缩放不出问题
        GameObject weaponObj = Instantiate(weapon, weaponPos, false);
        nowWeapon = weaponObj.GetComponent<WeaponObj>();
        nowWeapon.SetFather(this);
    }

    public override void Dead()
    {
        //玩家死亡
        Time.timeScale = 0;
        LosePanel.Instance.ShowMe();
    }
}
